#ifndef PWORLD_H
#define PWORLD_H

#include <QObject>
#include <QVector>

#include <physics/pobject.h>
#include <physics/pship.h>

class PWorld : public QObject
{
    Q_OBJECT
public:
    explicit PWorld(double width, double height, QObject *parent = 0);

    void tick(double t);

    void addObject(PObject *object);
    void delObject(PObject *object);

    QVector<PObject*> getObjects() const;
    double getWidth() const;
    double getHeight() const;

    PShip *getShip(QString name) const;

    void serialize(QDomDocument *doc, QDomElement *e) const;

    static const double G = 1.1;

    static PWorld *deserialize(QDomNode e, QObject *parent = 0);

signals:

public slots:

private:
    QVector<PObject*> myObjects;
    QVector<PShip*> myShips;

    inline void checkCollision(PObject *obj1, PObject *obj2);
    inline void processObject(PObject *obj1);
    void processShip(PShip *obj1);

    int timeCycle;

    double myWidth;
    double myHeight;
};

#endif // PWORLD_H
